from django.contrib import admin

# Register your models here.

import re
from .models import WechatVerify,VerifyHost

class WechatVerifyAdmin(admin.ModelAdmin):
    raw_id_fields = ['host']
    fields = ['host','file','desc']
    list_display = ['id','verify_host','file_url','desc']
    def verify_host(self,obj):
        return obj.host.website

    def file_url(self,obj):
        base = re.sub('/$','',obj.host.website)

        url =  base +'/'+ obj.file.name.split('/')[-1]
        return url
        # return '<a href="{url}">{name}</a>'.format(url=url,name=obj.file.name)




class VerifyHostAdmin(admin.ModelAdmin):
    fields = ['name','website','ansible_group','dest','desc']
    list_display = ['id','name','website','ansible_group','dest','desc']





admin.site.register(VerifyHost,VerifyHostAdmin)
admin.site.register(WechatVerify,WechatVerifyAdmin)